<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('测站点修改')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-meter-edit" th:object="${basicMeter}">
            <input name="meterId" th:field="*{meterId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">所属住房：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="houseId" type="hidden" th:field="*{houseId}"/>
                        <input class="form-control" type="text" onclick="selectHouseTree()" id="treeName" readonly="true" th:field="*{houseName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系人</label>
                <div class="col-sm-8">
                    <input name="leader" th:field="*{leader}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系电话</label>
                <div class="col-sm-8">
                    <input name="phone" th:field="*{phone}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">热表表号</label>
                <div class="col-sm-8">
                    <input name="meterNo" th:field="*{meterNo}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">采集设备</label>
                <div class="col-sm-8">
                    <select id="deviceId" name="deviceId" class="form-control">
                        <option th:each="device:${deviceList}" th:value="${device.deviceId}" th:text="${device.deviceCode}" th:field="*{deviceId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">热表厂家</label>
                <div class="col-sm-8">
                    <select name="meterFactory" class="form-control m-b" th:with="type=${@dict.getType('meter_factory')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{meterFactory}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "basic/meter";
        $("#form-meter-edit").validate({
            onkeyup: false,
            rules: {
                meterNo: {
                    remote: {
                        url: prefix + "/checkMeterUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "meterId": function() {
                                return $("#meterId").val();
                            },
                            "meterNo": function() {
                                return $.common.trim($("#meterNo").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
            },
            messages: {
                "meterNo": {
                    remote: "表号已存在"
                }
            },
            focusCleanup: true
        });

        /*住房信息-编辑-选择父住房信息树*/
        function selectHouseTree() {
            var options = {
                title: '住房信息选择',
                width: "380",
                url: ctx + "basic/house/selectHouseAllTree",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = $.modal.getChildFrame(index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                $.modal.close(index);
            }
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-meter-edit').serialize());
            }
        }
    </script>
    </body>
</html>